package com.zzoranor.presentationserver;

import protocols.ProtocolsProto.AddCharacter;
import protocols.ProtocolsProto.CharacterMessage;
import protocols.ProtocolsProto.ClientToServerMessage;

public class ClientToServerMessageHandler {
	ServerDispatcher serverDispatcher;
	
	
	public ClientToServerMessageHandler(ServerDispatcher serverDispatcher)
	{
		this.serverDispatcher = serverDispatcher;
	}
	
	public void handle(ClientInfo clientInfo, ClientToServerMessage message)
	{
		
		
		String returnMessage = message.getHelloWorld().getHelloWorld();
		if(message.hasCharacterMessage())
		{
			CharacterMessage cMessage = message.getCharacterMessage();
			if(cMessage.hasAddCharacter())
			{
				AddCharacter addCharacterMessage = cMessage.getAddCharacter();
				
				String name = "Captain Placeholder";
				if(addCharacterMessage.hasCharName())
				{
					name = addCharacterMessage.getCharName();
				}
				
				returnMessage = "Character Created: " + name;
			}
		}
		
		serverDispatcher.dispatchMessage(clientInfo, returnMessage);
		
		
	}
	
}
